//
//  ServiceManagementVC.m
//  Toyota
//
//  Created by ld on 2024/6/25.
//

#import "ServiceManagementVC.h"
#import "RealnameManagementVC.h"
#import "ServiceConManagementVC.h"
#import "Definition.h"
#import "SGPagingView.h"
@interface ServiceManagementVC ()<SGPageTitleViewDelegate, SGPageContentScrollViewDelegate> {
    RealnameManagementVC * realnameManage;
    ServiceConManagementVC * serviceManage;
}
@property (nonatomic, strong) SGPageTitleView *pageTitleView;
@property (nonatomic, strong) SGPageContentScrollView *pageContentScrollView;

@property(nonatomic,assign)NSInteger selectedIndex;
@property(nonatomic,strong)NSMutableArray * viewControllerArr;
@property(nonatomic,strong)NSArray *titleArr;

@end

@implementation ServiceManagementVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kColorFFFFFF;
    self.title = @"服务管理";
    [self initUI];
    //    CYScalW
    // Do any additional setup after loading the view.
}



- (void)initUI{
    realnameManage = [[RealnameManagementVC alloc]init];
    serviceManage = [[ServiceConManagementVC alloc]init];
    SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure];
    configure.titleFont = fontSize(CYScalW(14));
    configure.titleSelectedFont = fontBold(CYScalW(14));
    configure.titleColor = kColor969696;
    configure.titleSelectedColor = kColor141414;
    configure.indicatorColor = kColorEB0A1E;
    configure.indicatorHeight = 0;
    configure.titleGradientEffect = YES;
    configure.indicatorStyle = SGIndicatorStyleFixed;
    configure.indicatorFixedWidth = 12;
    configure.indicatorHeight = 3;
    configure.indicatorCornerRadius = 2;
    configure.bottomSeparatorColor = kColorFFFFFF;
    configure.needBounces = NO;
    configure.indicatorToBottomDistance = 2;
    
    _viewControllerArr = [NSMutableArray arrayWithObjects:realnameManage, serviceManage, nil];
    _titleArr = @[@"实名认证管理", @"服务契约管理"];

    self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, 0, ScreenWidth, 40) delegate:self titleNames:_titleArr configure:configure andBgViewColor:[UIColor whiteColor]];
    [self.view addSubview:_pageTitleView];
    
    _pageTitleView.selectedIndex = 0;
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.pageTitleView resetTitle:self.titleArr[0] forIndex:0];
    });
    
    CGFloat contentViewHeight = ScreenHeight - CGRectGetMaxY(_pageTitleView.frame);
    self.pageContentScrollView = [[SGPageContentScrollView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_pageTitleView.frame), ScreenWidth, contentViewHeight) parentVC:self childVCs:_viewControllerArr];
    _pageContentScrollView.delegatePageContentScrollView = self;
    [self.view addSubview:_pageContentScrollView];
    
}

- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
    [self.pageContentScrollView setPageContentScrollViewCurrentIndex:selectedIndex];
}

- (void)pageContentScrollView:(SGPageContentScrollView *)pageContentScrollView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex {
    [self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];
}

- (void)pageContentScrollView:(SGPageContentScrollView *)pageContentScrollView index:(NSInteger)index {
    /// 说明：在此获取标题or当前子控制器下标值
    NSLog(@"index - - %ld", (long)index);
    _selectedIndex = index;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
